let loginForm = document.querySelector(".denglu");
let loginUser = document.querySelector("#loginUser");
let loginPass = document.querySelector("#loginPass");

loginForm.onsubmit = function (e) {
  var e = e || window.event;
  e.returnValue = false;

  let p = pAjax({
    url: "/sa/login.php",
    type: "post",
    data: {
      username: loginUser.value,
      password: loginPass.value,
    },
  });
  p.then((res) => {
    res = JSON.parse(res);
    if (res.code) {
      setCookie("login", loginUser.value);
      let url = localStorage.getItem("url");
      localStorage.removeItem("url");
      location.href = url ? url : "../html/index.html";
    } else {
      alert("用户名或者密码错误");
    }
  });
};

// 回到顶部
var dingbu = document.querySelector(".dingbu");
window.onscroll = function () {
  var height = window.innerHeight + scrollY;
  if (height > window.innerHeight) {
    dingbu.style.display = "block";
    dingbu.onclick = function () {
      scrollTo({ top: 0, behavior: "smooth" });
    };
  } else {
    dingbu.style.display = "none";
  }
};
